import { ref } from "vue"
import { useRoute, onBeforeRouteUpdate } from "vue-router"
import { getSedCategoryAPI } from "@/apis/category"

export function useCategory() {
  const route = useRoute()
  const sedCategoryList = ref({})
  const getSedCategory = async (id = route.params.id) => {
    const res = await getSedCategoryAPI(id)
    sedCategoryList.value = res.result
  }
  getSedCategory()
  onBeforeRouteUpdate((to) => {
    getSedCategory(to.params.id)
  })
  return {
    sedCategoryList,
  }
}
